package com.example.demo01.service;

import com.example.demo01.bean.Car;
import com.example.demo01.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author liuyuan
 * @Date 2022/7/16 10:53 AM
 * @Version 1.0
 */
@Service
public class CarServiceImpl implements  CarService{
    @Autowired
    CarMapper carMapper;
    @Override
    public void add(Long goodId) {
        Car byId = carMapper.getById(goodId);
        if(byId == null){
            Car car = new Car();
            car.setGoodId(goodId);
            car.setNum(1);
            carMapper.insert(car);
        }else {
            Integer num = byId.getNum();
            num++;
            byId.setNum(num);
            carMapper.update(byId);
        }

    }
}
